//
//  WmcAspectRatioBtn.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/3/3.
//

import UIKit
import YPBedrock
import YPGraphicEngine

/// 画幅比例按钮
class WmcAspectRatioBtn: WmcTopImgBottomTextBtn {
    typealias AspectRatio = YPGESunglasses.AspectRatio

    // Internal

    /// 事件Block
    var actionBlock: YPBlock.Action<WmcAspectRatioBtn>?

    /// 画幅比例类型
    var aspectRatio: AspectRatio = .ar_4_3 {
        didSet {
            self.title = aspectRatio.info.title
            self.imageView.image = aspectRatio.info.image
            self.imageView.yp.set(tintColor: aspectRatio.info.color)
            self.textColor = aspectRatio.info.color
        }
    }

    static func Create() -> WmcAspectRatioBtn {
        let btn = WmcAspectRatioBtn()
        btn.font = 12.wmc_font
        btn.imgTextSpacing = 2
        btn.imgSize = 24
        btn.yp.addEvent { btn in
            btn.clickAspectRatio()
            btn.actionBlock?(btn)
        }
        btn.aspectRatio = .ar_4_3
        return btn
    }

    /// 递增事件
    func clickAspectRatio() {
        let new = aspectRatio.rawValue
        if let newCase = AspectRatio(rawValue: new + 1) {
            aspectRatio = newCase
        } else {
            aspectRatio = .ar_4_3
        }
    }
}
